<?php

namespace App\Admin\Forms\User;

use App\Models\User;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Http\JsonResponse;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\Hash;

class ResetPasswordForm extends Form implements LazyRenderable
{
    use LazyWidget;

    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return JsonResponse
     */
    public function handle(array $input): JsonResponse
    {
        $user = User::query()->where('id', '=', $this->payload['id'])->first();
        $user->payment_password = Hash::make($input['payment_password']);
        $user->save();
        return $this
            ->response()
            ->success(trans('admin.succeeded'))
            ->refresh();
    }

    /**
     * Build a form here.
     */
    public function form()
    {
        $this->password('payment_password')->required();
    }

}
